﻿using BigMonitoringWarningApi.Tool.Extension;
using GYCTOAManagementSystemNewApi.Model.Tool;
using GYCTOAManagementSystemNewApi.Model.ViewModel;
using System.Collections.Generic;
using System.Linq;

namespace GYCTOAManagementSystemNewApi.Service
{
    public class ToolService
    {
        public static List<T> FindChild<T>(List<T> list, int parent=0) where T : ParentModel, new()
        { 
            List<T> pageValues = new List<T>();
            if (list.Where(o => o.PrId.ToInt() == parent).Count() > 0)
            {
                foreach (var item in list.Where(o => o.PrId.ToInt() == parent).ToList())
                {
                    pageValues.Add(item);
                    pageValues.AddRange(FindChild(list, item.Id.ToInt()));
                }
            }
            return pageValues;
        }  
    }
}
